package com.zlsy.secondtime.threadpool;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @author zhouliang
 * @date 2020/10/23 8:46
 */
public class FixedThreadPoolOOM {
    /**
     * 通过设置有限的内存分配参数：-Xmx8m -Xms8m
     * 演示newFixedThreadPool发生OOM的情况
     */
    public static void main(String[] args) {
        ExecutorService service = Executors.newFixedThreadPool(1);
        for (int i = 0; i < Integer.MAX_VALUE; i++) {
            service.execute(new Runnable() {
                @Override
                public void run() {
                    try {
                        Thread.sleep(100000000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            });
        }
        service.shutdown();
    }
}
